\documentclass[12pt,a4paper,openany]{book}

% Comprehensive preamble for professional technical report
\usepackage{amsmath, amssymb, amsthm}
\usepackage[margin=2.5cm]{geometry}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{listings}
\usepackage[svgnames]{xcolor}
\usepackage{hyperref}
\usepackage{multicol}
% Load algorithmicx for compatibility with existing code
\usepackage{algorithm}
\usepackage{algpseudocode}

% Define compatibility macros for algorithm2e commands used in some chapters
\providecommand{\Input}[1]{\Require #1}
\providecommand{\Output}[1]{\Ensure #1}
\providecommand{\KwTo}{\textbf{ to }}
\providecommand{\tcp}[1]{\Comment{#1}}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{enumerate}
\usepackage{subcaption}
\usepackage{float}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{fancyhdr}
\usepackage{setspace}
\usetikzlibrary{positioning,shapes.geometric,arrows,calc,patterns,decorations.pathmorphing,decorations.markings,trees}
\pgfplotsset{compat=1.17}

% Page setup
\geometry{a4paper, left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm}
\setlength{\headheight}{15pt}

% Hyperref setup
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,      
    urlcolor=cyan,
    citecolor=green,
    pdftitle={C++ Function Call Tree Analysis: Technical Documentation of MCP-Based Static Analysis System},
    pdfauthor={C++ Function Call Tree Analysis Development Team},
    pdfsubject={Static Code Analysis, Function Call Trees, Model Context Protocol, C++ Parsing, Software Architecture},
    pdfkeywords={C++, Static Analysis, Call Graph, MCP, Clang AST, LibClang, Code Analysis, Software Engineering},
    pdfpagemode=UseOutlines
}

% Listings setup for code highlighting
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{cpp}{
    backgroundcolor=\color{backcolour},   
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2,
    language=C++
}

\lstdefinestyle{python}{
    backgroundcolor=\color{backcolour},   
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2,
    language=Python
}

\lstset{style=cpp}

% Algorithm setup for algpseudocode
% Using built-in commands: \State, \For, \If, \While, etc.
% Define try-catch block commands
\algnewcommand\algorithmictry{\textbf{try}}
\algnewcommand\algorithmicCatch{\textbf{catch}}
\algnewcommand\algorithmicendtry{\textbf{end try}}
\algnewcommand\Try{\algorithmictry}
\algnewcommand\Catch[1]{\algorithmicCatch\ #1}
\algnewcommand\EndTry{\algorithmicendtry}

% Theorem environments
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{algorithmdef}[theorem]{Algorithm}
\newtheorem{example}[theorem]{Example}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{note}[theorem]{Note}

% Custom commands for common mathematical notation
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\norm}[1]{\left\|#1\right\|}
\newcommand{\inner}[2]{\langle #1, #2 \rangle}
\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\abs}[1]{\left|#1\right|}
\newcommand{\eps}{\varepsilon}
\newcommand{\bigO}[1]{\mathcal{O}(#1)}
\newcommand{\complexity}[1]{\Theta(#1)}

% Custom commands for call graph notation
\newcommand{\callgraph}{\mathcal{G}}
\newcommand{\functions}{\mathcal{F}}
\newcommand{\calls}{\mathcal{C}}
\newcommand{\nodes}{\mathcal{V}}
\newcommand{\edges}{\mathcal{E}}

% Header and footer setup
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE]{\leftmark}
\fancyhead[RO]{\rightmark}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}

\begin{document}

% Title page
\begin{titlepage}
\centering
\vspace*{2cm}

{\Huge\bfseries C++ Function Call Tree Analysis}\\[0.5cm]
{\Large Technical Documentation of MCP-Based Static Analysis System}\\[2cm]

{\large\textbf{Development Team}}\\[0.5cm]
{\large C++ Function Call Tree Analysis Project}\\[2cm]

% \includegraphics[width=0.3\textwidth]{placeholder_logo}\\[1cm]
% Note: Replace with actual logo if available

{\large \today}\\[2cm]

\vfill

{\large\textbf{Abstract}}\\[0.5cm]
\begin{minipage}{0.8\textwidth}
\centering
This technical report presents a comprehensive analysis of the C++ Function Call Tree Analysis system, a sophisticated Model Context Protocol (MCP) server designed for static code analysis of C/C++ codebases. The system combines multiple parsing approaches, including regex-based pattern matching and Clang AST analysis, to generate detailed function call trees and perform comprehensive validation of code structure. This document provides detailed technical specifications, architectural design principles, algorithmic foundations, and implementation strategies for the complete analysis framework.
\end{minipage}

\vfill

\end{titlepage}

% Table of contents
\tableofcontents
\listoffigures
\listofalgorithms
\listoftables

\mainmatter

% Include chapters
\include{chapters/ch1_introduction}
\include{chapters/ch2_architecture_design}
\include{chapters/ch3_parsing_engines}
\include{chapters/ch4_analysis_algorithms}
\include{chapters/ch5_validation_framework}
\include{chapters/ch6_mcp_integration}
\include{chapters/ch7_conclusions}

\end{document}